package com.zhkj.txg.module.login.ui

import android.graphics.Bitmap
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.zhkj.txg.R
import com.zhkj.txg.base.GlideApp
import com.zhkj.txg.utils.ImageUtils
import kotlinx.android.synthetic.main.layout_guide.*

class GuideFragment : Fragment() {

    companion object {
        private val TYPE = "type"
        private val IMAGE = "image"
        fun newInstance(type: Int): GuideFragment {
            return GuideFragment().apply {
                arguments = bundleOf(TYPE to type)
            }
        }

        fun newInstance(image: String): GuideFragment {
            return GuideFragment().apply {
                arguments = bundleOf(IMAGE to image)
            }
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val type = arguments?.getInt(TYPE, 0)
//        return inflater.inflate(
//            when (type) {
//                1 -> R.layout.layout_guide_2
//                2 -> R.layout.layout_guide_3
//                3 -> R.layout.layout_guide_4
//                else -> R.layout.layout_guide_1
//            }, container, false
//        )
        return inflater.inflate(
            R.layout.layout_guide, container, false
        )
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

//        GlideApp.with(this).asBitmap().centerCrop().load(arguments?.getString(IMAGE) ?: "")
//            .placeholder(R.drawable.ic_loading).error(R.drawable.ic_loading).into(object : SimpleTarget<Bitmap>() {
//                override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
//                    ivGuideImageView.setImageBitmap(resource)
//                }
//            })

        GlideApp.with(this@GuideFragment).load(arguments?.getString(IMAGE) ?: "")
            .placeholder(R.drawable.ic_loading).error(R.drawable.ic_loading).into(ivGuideImageView)
//        ImageUtils.loadImage(this@GuideFragment, ivGuideImageView, arguments?.getString(IMAGE) ?: "")

    }
}